using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Bifrost;
using DevComponents.Editors;

namespace TextEditor.TextDocument.Control
{
    public partial class frmSelectSection : DevComponents.DotNetBar.Office2007Form
    {
        static DataTable sectionDt = null;
        static string sql = "select a.sid,a.section_name from T_SECTIONINFO a inner join T_SECTION_AREA b on a.sid=b.sid where ENABLE_FLAG='Y' order by a.section_name,a.sid";
        public frmSelectSection(string id)
        {
            InitializeComponent();
            if (sectionDt == null)
            {
                sectionDt = App.GetDataSet(sql).Tables[0];
            }
            bindTable(id);
        }

        void bindTable(string id)
        {
            int index = 0;
            if (sectionDt != null && sectionDt.Rows.Count > 0)
            {
                int x =  0;
                foreach (DataRow _row in sectionDt.Rows)
                {
                    ComboItem item = new ComboItem();
                    item.Text = _row[1].ToString();
                    item.Tag = _row[0].ToString();
                    this.cbSectionList.Items.Add(item);
                    if (item.Tag.ToString() == id)
                    {
                        index = x;
                    }
                    x++;
                }
            }
            this.cbSectionList.SelectedIndex = index;
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            ComboItem item = (ComboItem)this.cbSectionList.SelectedItem;
            if (item != null)
            {
                this.SectionId = item.Tag.ToString();
                this.SectionName = item.Text.ToString();
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private string sectionName= "";
        public string SectionName
        {
            set
            {
                sectionName = value;
            }
            get 
            {
                return sectionName;
            }
        }

        private string sectionId = "";
        public string SectionId
        {
            set
            {
                sectionId = value;
            }
            get
            {
                return sectionId;
            }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}